home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue45 / Construc / INIMOD.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-11-02  |  1.4 KB  |  60 lines

  1. unit IniMod;
  2. interface
  3. uses
  4.   SysUtils, Classes;
  5.  
  6. type
  7.   ELoginFailed = class(Exception);
  8.  
  9.   procedure GetLines(const User, Passw: String;
  10.                      Lines: TStrings); // raises ELoginFailed
  11.  
  12.   procedure SetLines(const User,Passw: String;
  13.                      Lines: TStrings); // raises ELoginFailed
  14.  
  15. implementation
  16. uses
  17.   IniFiles;
  18.  
  19. var
  20.   IniFile: TIniFile = nil;
  21.  
  22. procedure GetLines(const User,Passw: String; Lines: TStrings);
  23. var
  24.   i: Integer;
  25. begin
  26.   if (User <> '') and
  27.      (IniFile.ReadString(User,'password','') = Passw) then
  28.   begin
  29.     Lines.Clear;
  30.     for i:=1 to IniFile.ReadInteger(User,'lines',0) do
  31.       Lines.Add(IniFile.ReadString(User,IntToStr(i),''))
  32.   end
  33.   else
  34.     raise ELoginFailed.Create('Login failed.')
  35. end {GetLines};
  36.  
  37. procedure SetLines(const User,Passw: String; Lines: TStrings);
  38. var
  39.   i: Integer;
  40. begin
  41.   if (User <> '') and
  42.      (IniFile.ReadString(User,'password','') = Passw) then
  43.   begin
  44.     IniFile.EraseSection(User);
  45.     IniFile.WriteString(User,'password',Passw); { reset password }
  46.     IniFile.WriteInteger(User,'lines',Lines.Count); { linescount }
  47.     for i:=1 to Lines.Count do
  48.       IniFile.WriteString(User,IntToStr(i),Lines[Pred(i)])
  49.   end
  50.   else
  51.     raise ELoginFailed.Create('Permission denied.')
  52. end {SetLines};
  53.  
  54. initialization
  55.   IniFile := TIniFile.Create('.\BobNotes.ini');
  56. finalization
  57.   IniFile.Free;
  58.   IniFile := nil
  59. end.
  60.